import { MenuBgParams as Params } from '@swda/configs/params'
// set parameters
const {
    bgBitmapMenu,
    bgBitmapItem,
    bgBitmapSkill,
    bgBitmapEquip,
    bgBitmapStatus,
    bgBitmapShop,
    bgBitmapMusic,
    bgBitmapKey,
    bgBitmapGamePad,
    bgBitmapSynthesis,
    bgBitmapOptions,
    bgBitmapQuest,
    bgBitmapGameEnd,
    menuOpacity,
    itemOpacity,
    skillOpacity,
    equipOpacity,
    statusOpacity,
    shopOpacity,
    keyOpacity
} = Params;


const setBgBitmap = (target, bitmapUrl) => {
    if (!bitmapUrl) return;

    target._backgroundSprite = new Sprite();
    const bitmap = ImageManager.loadBitmap('img/system/UI/', bitmapUrl);
    target._backgroundSprite.bitmap = bitmap
    target.addChild(target._backgroundSprite);
}

//
// make transparent windows for each scenes in menu.
//
var _Scene_Menu_create = Scene_Menu.prototype.create;
Scene_Menu.prototype.create = function () {
    _Scene_Menu_create.call(this);
    // make transparent for all windows at menu scene.
    this._statusWindow.opacity = menuOpacity;
    this._goldWindow.opacity = menuOpacity;
    this._commandWindow.opacity = menuOpacity;

};

var _Scene_Item_create = Scene_Item.prototype.create;
Scene_Item.prototype.create = function () {
    _Scene_Item_create.call(this);
    this._helpWindow.opacity = itemOpacity;
    this._categoryWindow.opacity = itemOpacity;
    this._itemWindow.opacity = itemOpacity;
    this._actorWindow.opacity = itemOpacity;
};

var _Scene_Skill_create = Scene_Skill.prototype.create;
Scene_Skill.prototype.create = function () {
    _Scene_Skill_create.call(this);
    this._helpWindow.opacity = skillOpacity;
    this._skillTypeWindow.opacity = skillOpacity;
    //this._statusWindow.opacity = skillOpacity;
    this._itemWindow.opacity = skillOpacity;
    this._actorWindow.opacity = skillOpacity;
};

var _Scene_Fu_create = Scene_Fu.prototype.create;
Scene_Fu.prototype.create = function () {
    _Scene_Fu_create.call(this);
    this._helpWindow.opacity = skillOpacity;
    //this._statusWindow.opacity = skillOpacity;
    this._itemWindow.opacity = skillOpacity;
    //this._actorWindow.opacity = skillOpacity;
};

var _Scene_Equip_create = Scene_Equip.prototype.create;
Scene_Equip.prototype.create = function () {
    _Scene_Equip_create.call(this);
    this._helpWindow.opacity = equipOpacity;
    this._statusWindow.opacity = equipOpacity;
    this._commandWindow.opacity = equipOpacity;
    this._slotWindow.opacity = equipOpacity;
    this._itemWindow.opacity = equipOpacity;
    this._compareWindow.opacity = equipOpacity;
};

var _Scene_Status_create = Scene_Status.prototype.create;
Scene_Status.prototype.create = function () {
    _Scene_Status_create.call(this);
    this._statusWindow.opacity = statusOpacity;
};

var _Scene_Shop_create = Scene_Shop.prototype.create;
Scene_Shop.prototype.create = function () {
    _Scene_Shop_create.call(this);
    this._helpWindow.opacity = shopOpacity;
    this._categoryWindow.opacity = shopOpacity;
    this._statusWindow.opacity = shopOpacity;
    this._numberWindow.opacity = shopOpacity;
    this._buyWindow.opacity = shopOpacity;
    this._sellWindow.opacity = shopOpacity;
};

var _Scene_KeyConfig_create = Scene_KeyConfig.prototype.create;
Scene_KeyConfig.prototype.create = function () {
    _Scene_KeyConfig_create.call(this);
    this._helpWindow.opacity = keyOpacity;
    this._configWindow.opacity = keyOpacity;
    this._actionWindow.opacity = keyOpacity;
};

//
// load bitmap that set in plugin parameter
//
var _Scene_Menu_createBackground = Scene_Menu.prototype.createBackground;
Scene_Menu.prototype.createBackground = function () {
    _Scene_Menu_createBackground.call(this);
    setBgBitmap(this, bgBitmapMenu)
};

var _Scene_Item_createBackground = Scene_Item.prototype.createBackground;
Scene_Item.prototype.createBackground = function () {
    _Scene_Item_createBackground.call(this);
    setBgBitmap(this, bgBitmapItem)
};

var _Scene_Skill_createBackground = Scene_Skill.prototype.createBackground;
Scene_Skill.prototype.createBackground = function () {
    _Scene_Skill_createBackground.call(this);
    setBgBitmap(this, bgBitmapSkill)
};

var _Scene_Fu_createBackground = Scene_Fu.prototype.createBackground;
Scene_Fu.prototype.createBackground = function () {
    _Scene_Fu_createBackground.call(this);
    setBgBitmap(this, bgBitmapSkill)
};

var _Scene_Equip_createBackground = Scene_Equip.prototype.createBackground;
Scene_Equip.prototype.createBackground = function () {
    _Scene_Equip_createBackground.call(this);
    setBgBitmap(this, bgBitmapEquip)
};

var _Scene_Status_createBackground =
    Scene_Status.prototype.createBackground;
Scene_Status.prototype.createBackground = function () {
    _Scene_Status_createBackground.call(this);
    setBgBitmap(this, bgBitmapStatus)
};

var _Scene_Shop_createBackground =
    Scene_Shop.prototype.createBackground;
Scene_Shop.prototype.createBackground = function () {
    _Scene_Shop_createBackground.call(this);
    setBgBitmap(this, bgBitmapShop)
};

var _Scene_MusicMenu_createBackground =
Scene_MusicMenu.prototype.createBackground;
Scene_MusicMenu.prototype.createBackground = function () {
    _Scene_MusicMenu_createBackground.call(this);
    setBgBitmap(this, bgBitmapMusic)
};

var _Scene_Synthesis_createBackground =
Scene_Synthesis.prototype.createBackground;
    Scene_Synthesis.prototype.createBackground = function () {
    _Scene_Synthesis_createBackground.call(this);
    setBgBitmap(this, bgBitmapSynthesis)
};

//var _Scene_Options_createBackground =
//    Scene_Options.prototype.createBackground;
Scene_Options.prototype.createBackground = function () {
    this._backgroundSprite = new Sprite();
    if(SceneManager.isTitleOptions())
        this._backgroundSprite.bitmap = ImageManager.loadTitle1('Title0');
    else
        this._backgroundSprite.bitmap = SceneManager.backgroundBitmap();
    this.addChild(this._backgroundSprite);
    setBgBitmap(this, bgBitmapOptions)
};

var _Scene_KeyConfig_createBackground =
    Scene_KeyConfig.prototype.createBackground;
Scene_KeyConfig.prototype.createBackground = function () {
    _Scene_KeyConfig_createBackground.call(this);
    if(SceneManager.isTitleOptions())
        this._backgroundSprite.bitmap = ImageManager.loadTitle1('Title0');
    else
        this._backgroundSprite.bitmap = SceneManager.backgroundBitmap();
    this.addChild(this._backgroundSprite);
    setBgBitmap(this, bgBitmapKey)
};

var _Scene_GamepadConfig_createBackground =
Scene_GamepadConfig.prototype.createBackground;
Scene_GamepadConfig.prototype.createBackground = function () {
    _Scene_GamepadConfig_createBackground.call(this);
    if(SceneManager.isTitleOptions())
        this._backgroundSprite.bitmap = ImageManager.loadTitle1('Title0');
    else
        this._backgroundSprite.bitmap = SceneManager.backgroundBitmap();
    this.addChild(this._backgroundSprite);
    setBgBitmap(this, bgBitmapGamePad)
};

var _Scene_Quest_createBackground =
    Scene_Quest.prototype.createBackground;
Scene_Quest.prototype.createBackground = function () {
    _Scene_Quest_createBackground.call(this);
    setBgBitmap(this, bgBitmapQuest)
};

var _Scene_GameEnd_createBackground =
    Scene_GameEnd.prototype.createBackground;
Scene_GameEnd.prototype.createBackground = function () {
    _Scene_GameEnd_createBackground.call(this);
    setBgBitmap(this,bgBitmapGameEnd)
};